package com.hzw.saas.web.shell.listener;

import java.util.Objects;

import com.hzw.saas.common.config.annotation.SysLog;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.messaging.SessionConnectedEvent;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 *   SessionConnectEvent在代理发送一个STOMP CONNECTED帧以响应CONNECT之后不久发布。
 *   此时，可以认为STOMP会话已完全建立
 * </p>
 *
 * @author sonam
 * @since 2021/5/21 16:58
 */
@Slf4j
@Component
public class SessionConnectedListener implements ApplicationListener<SessionConnectedEvent> {

    @Override
    @SysLog(operation = "Websocket建立了连接", mode = 1)
    public void onApplicationEvent(SessionConnectedEvent event) {
        String name = Objects.nonNull(event.getUser()) ? event.getUser().getName() : "unknown";
        log.info(name + "和Websocket建立了连接");
    }

}
